#include "QtBox2DBaseItem.h"

QtBox2DBaseItem::QtBox2DBaseItem(QtBox2DScene* scene, QGraphicsItem* parent/* = 0*/):
	QAbstractGraphicsShapeItem(parent)
{
	scene->addItem(this);
}

void QtBox2DBaseItem::generateName(QtBox2DScene* scene)
{
	static ulong s_nCount = 0; 
	QString tmpName = QString("Box2DItem_%1").arg(s_nCount++);
	QStringList exitItems;
	foreach(QGraphicsItem* item, scene->items())
	{
		QtBox2DBaseItem* pItem = dynamic_cast<QtBox2DBaseItem*>(item);
		if (pItem)
		{
			exitItems.push_back(pItem->getName());
		}
	}

	while (exitItems.contains(tmpName))
	{
		tmpName = QString("Box2DItem_%1").arg(s_nCount++);
	}
	mName = tmpName;
}